﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;
using VOL.Core.Configuration;
using VOL.Core.Extensions;

namespace VOL.Core.Utilities
{
    //{"choices":[{"finish_reason":"stop","index":0,"logprobs":null,"message":{"content":"\n\n你好！很高兴为您服务。有什么我可以帮您的吗？","reasoning_content":"好的，用户发来了“你好”，这是常见的中文问候。首先，我需要用自然、友好的中文回应。保持礼貌，同时也要符合助手的角色。可能需要进一步询问用户有什么需要帮助的地方，但用户可能只是打个招呼。要确保回应简洁，不冗长。另外，注意使用口语化的表达，避免过于正式。可能需要准备回答后续问题，所以保持开放式的结尾比较好。比如“有什么可以帮您的吗？”这样既回应了问候，又引导用户提出需求。同时，检查是否有拼写错误，确保回复正确。现在组织语言，开始回复。\n","role":"assistant"}}],"created":1741312133,"id":"021741312127876862e5aa6e4924ad5d250c3fdbdee85c8a959c0","model":"deepseek-r1-250120","service_tier":"default","object":"chat.completion","usage":{ "completion_tokens":137,"prompt_tokens":10,"total_tokens":147,"prompt_tokens_details":{ "cached_tokens":0},"completion_tokens_details":{ "reasoning_tokens":124} }}
    public class RequestAI
    {
        public List<choices> choices { get; set; }
        public int created { get; set; }
        public string id { get; set; }
        public string model { get; set; }
        public string service_tier { get; set; }
      //  public string object { get; set; }
        //public string object { get; set; }
        //    public List<MesAI> messages { get; set; }

    }
    public class choices
    {
        public string finish_reason { get; set; }
        public int index { get; set; }
        public message message { get; set; }
    }
    public class message
    {
        public string content { get; set; }
        public string reasoning_content { get; set; }
        public string role { get; set; }
    }

    public class Wheres
    {
        //  [{"name":"ProjectCode","value":"444","displayType":"text"},{"name":"ProjectName","value":"444","displayType":"text"}]
        public string name { get; set; }
        public string value { get; set; }
        public string displayType { get; set; }
    }
    public static class MailHelper
    {
        private static string address { get; set; }
        private static string authPwd { get; set; }
        private static string name { get; set; }
        private static string host { get; set; }
        private static int port;
        private static bool enableSsl { get; set; }
        static MailHelper()
        {
            IConfigurationSection section= AppSetting.GetSection("Mail");
            address = section["Address"];
            authPwd = section["AuthPwd"];
            name = section["Name"];
            host = section["Host"];
            port = section["Port"].GetInt();
            enableSsl = section["EnableSsl"].GetBool();
        }

        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">内容</param>
        /// <param name="list">收件人</param>
        public static void Send(string title, string content, params string[] list)
        {
            MailMessage message = new MailMessage
            {
                From = new MailAddress(address, name)//发送人邮箱
            };
            foreach (var item in list)
            {
                message.To.Add(item);//收件人地址
            }

            message.Subject = title;//发送邮件的标题

            message.Body = content;//发送邮件的内容
            //配置smtp服务地址
            SmtpClient client = new SmtpClient
            {
                Host = host,
                Port = port,//端口587
                EnableSsl = enableSsl,
                //发送人邮箱与授权密码
                Credentials = new NetworkCredential(address, authPwd)
            };
            client.Send(message);
        }
    }
}
